home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 7
/
Amiga Format AFCD07 (Dec 1996, Issue 91).iso
/
in_the_mag
/
blitz
/
listing.doc
Wrap
Text File
|
1996-09-16
|
11KB
|
843 lines
;
;
; HTML viewer v0.9
;
; (C) 1996 John Kennedy for Amiga Format
;
;
; Define Constants
#screen_height=256 ; Assume a 512 by 256 screen
#limitx=560 ; How far across the screen text can go...
#limit_height=1200 ; Limit to size of screen to attempt
; Define list
NEWTYPE .linktype
x1.q
y1.q
x2.q
y2.q
address$
End NEWTYPE
Dim List hyperlinks.linktype(100)
NEWTYPE .picturetype
height.q
width.q
name$
align$
End NEWTYPE
Dim List pictures.picturetype(50)
; Rest of program...
Statement alert{t$,a$,b$,c$,d$}
; This procedure puts up a box
WTitle t$,t$
Window 1,100,100,300,100,$1002,t$,1,2
Use Window 1 ; Use the new window for i/o
NPrint ""
NPrint a$
NPrint b$
NPrint c$
NPrint d$
NPrint " * Click to continue *"
MouseWait ; Wait for a mouse click
Free Window 1 ; Shut the about window
Use Window 0 ; Return to main window!
End Statement
Function load{p$}
SHARED html$
SHARED count
html$=""
WTitle "Loading..","Loading.."
MaxLen path$=192
MaxLen name$=192
path$="blitz2:af"
pattern$="(#?html||#?htm)"
If p$=""
p$=ASLFileRequest$("HTML File to load",path$,name$,pattern$)
EndIf
count=0
flag=ReadFile(0,p$)
If flag=True
FileInput 0
While NOT Eof(0)
html$=html$+Inkey$(1)
count=count+1
Wend
Else
alert{"File Error"," Sorry, the File you requested"," could not be loaded.", " Please try again",""}
Function Return False
EndIf
Function Return True
End Function
; Start of Program!
; -----------------
; Open a screen
Screen 0,12,"Blitz Browser"
height=screen_height
Gosub open_display
WLocate 10,10
Print "Welcome to Blitz Browser"
Repeat
WTitle "Waiting","Waiting"
Select WaitEvent
Case $100 ; Menu operation
Select ItemHit
Case 0; The Load option
If load{""}=True Then Gosub process
Case 1; The Save option
; Some day
Case 2; The About option
alert{"About"," ","HTML Viewer","Early alpha"," "}
Case 3; The Quit option
Goto goodbye
End Select
Case $200 ; Close gadget selected
Goto goodbye
Case $40 ; Scroll bar clicked
y.w=VPropPot(0,1)*height
PositionSuperBitMap 0,y.w
Redraw 0,1
Case $8 ; Mouse button
Gosub click
End Select
Forever
.process
WTitle "Processing HTML","Processing HTML"
WCls
Redraw 0,1
preview=On ; Nothing is printed, at first
ResetList hyperlinks()
For scan=1 To 2
ResetList pictures()
WColour 1
bold=Off
underline=Off
italic=Off
size=3
oldsize=3
original=3
offset=0
Gosub use_font
chunk$=""
startx=8
starty=8
xpos=startx
ypos=starty
sizey=13
WLocate xpos,ypos
lflag=Off
letter=1
tag=False
value=False
t$=""
v$=""
lnk$=""
While letter<count
l$=Mid$(html$,letter,1)
If Asc(l$)=10 l$=" "
If tag=True
If l$=">" Gosub process_tag:l$="":tag=False
t$=t$+l$
Else
If l$="<" tag=True:t$="":l$=""
If (l$<>"" AND value=True) v$=v$+l$
If (l$<>"" AND value=False) Then Gosub process_text
EndIf
letter=letter+1
Wend
If preview=On
; Close existing screen and re-open one the right size
CloseWindow 0
height=ypos
If height<#screen_height Then height=#screen_height
If height>#limit_height Then height=#screen_height
Gosub open_display
End If
preview=Off
Next scan
Return
.flush_text
If preview=Off Print chunk$:offset=WCursX
chunk$=""
Return
.process_text
chunk$=chunk$+l$
If (offset+(Len(chunk$)*sizex))>#limitx OR ((offset+(Len(chunk$)*sizex))>(#limitx-120) AND l$=" ")
If preview=Off Print chunk$
If preview=On
t$="Height:"+Str$(ypos)
WTitle t$,t$
End If
Gosub line_break
chunk$=""
EndIf
Return
.process_tag
t$=LCase$(t$)
t$=StripTrail$(t$,32)
t$=StripLead$(t$,32)
Select t$
Case "br"
Gosub flush_text
Gosub line_break
Case "p"
Gosub flush_text
Gosub new_paragraph
Case "hr"
Gosub flush_text
Gosub horizontal_line
Case "/b"
bold=Off:Gosub flush_text:Gosub use_font
Case "/u"
underlined=Off:Gosub flush_text:Gosub use_font
Case "/i"
italic=Off:Gosub flush_text:Gosub use_font
Case "b"
bold=On:Gosub flush_text:Gosub use_font
Case "u"
underlined=On:Gosub flush_text:Gosub use_font
Case "i"
italic=On:Gosub flush_text:Gosub use_font
Case "h1"
size=1:Gosub flush_text:Gosub use_font
Case "h2"
size=2:Gosub flush_text:Gosub use_font
Case "h3"
size=3:Gosub flush_text:Gosub use_font
Case "h4"
size=4:Gosub flush_text:Gosub use_font
Case "h5"
size=5:Gosub flush_text:Gosub use_font
Case "h6"
size=6:Gosub flush_text:Gosub use_font
Case "/h1"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "/h2"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "/h3"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "/h4"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "/h5"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "/h6"
size=0:Gosub flush_text:Gosub use_font:Gosub new_paragraph
Case "title" ; start capturing title
value=True:v$=""
Case "/title" ; title captured
If value=True
Gosub print_title:value=False
EndIf
Case "/a" ; link captured
If value=True AND preview=Off
Gosub make_link:value=False
EndIf
End Select
; Now tests for more fiddly commands
; Found the definition of a link
If preview=Off
If Left$(t$,2)="a " ; t$= is the entire tag link!
; process t$ to be only the link
f$=Chr$(34)
a=Instr(t$,f$)
t$=UnRight$(t$,a)
t$=StripTrail$(t$,34)
value=True:v$=""
lflag=On ; just to make sure tags are not nested
AddItem hyperlinks()
USEPATH hyperlinks()
\address=t$
\x1=WCursX
\y1=WCursY
EndIf
EndIf
If Left$(t$,3)="img"
Gosub picture
EndIf
Return
.click
; test to see if there is a link under the pointer
; when the user clicks the left mouse button
x=WMouseX
y=WMouseY+VPropPot(0,1)*height
ResetList hyperlinks()
l$=""
While (NextItem(hyperlinks()) AND l$="")
USEPATH hyperlinks()
If (x>=\x1 AND x<=\x2) AND (y>=\y1 AND y<=\y2)
l$=\address
EndIf
Wend
;If l$<>"" Then NPrint "The link is ",l$
If l$<>"" Then If load{l$}=True Then Gosub process
Return
;
; HTML COMMANDS
;
.horizontal_line
If preview=Off
y=WCursY
w=InnerWidth
WLine 8,y,(w-32),y,1
WLine 8,y+1,(w-32),y+1,2
EndIf
Gosub new_paragraph
Return
.picture
Gosub flush_text
Gosub new_paragraph
If preview=On
; Get details of picture (i.e. height)
; and add it to a list.
; Obtain filename from string
f$=Chr$(34)
a=Instr(t$,f$)
t$=UnRight$(t$,a)
a=Instr(t$,f$)
s$=Mid$(t$,a+1,Len(t$)-a)
t$=Left$(t$,a-1)
; Determine alignment (if any)
CaseSense Off
a$=""
If Instr(s$,"left")<>0 Then a$="L"
If Instr(s$,"center")<>0 Then a$="M"
If Instr(s$,"right")<>0 Then a$="R"
; Get info from file....
If Exists(t$)
ILBMInfo t$
If AddItem (pictures())
USEPATH pictures()
\height=ILBMHeight
\width=ILBMWidth
\name=t$
\align=a$
EndIf
Else
If AddItem (pictures())
USEPATH pictures()
\height=16
\width=16
\name="broken"
\align=a$
EndIf
EndIf
xpos=startx
ypos=ypos+h-sizey-sizey
WLocate xpos,ypos
offset=0
EndIf
If preview=Off
a=NextItem(pictures())
USEPATH pictures()
n$=\name
a$=\align
w=\width
h=\height
If n$="broken"
y=WCursY
x=WCursX
WBox x,y,x+16,y+16,2
WLine x,y,x+16,y+16,1
WLine x,y+16,x+16,y,1
Else
; Load in image as a "shape"
LoadShape 0,n$
; Place shape in main bitmap
y=WCursY
x=WCursX
WBlit 0,x,y
End If
xpos=startx
ypos=ypos+h-sizey-sizey
WLocate xpos,ypos
offset=0
End If
Gosub new_paragraph
Return
.print_title
v$=StripTrail$(v$,32)
v$=StripLead$(v$,32)
WTitle v$,v$
Return
.make_link
If preview=Off
Gosub flush_text
Gosub special_flush
USEPATH hyperlinks()
\x2=WCursX
\y2=WCursY+sizey
End If
;WBox \x1,\y1,\x2,\y2,2 ; Used for testing...
Return
.special_flush
WColour 2 ; Switch to new colour for links
For a=1 To Len(v$)
Print Mid$(v$,a,1)
If WCursX>(#limitx-128)
; At this point the text has wrapped, but
; a link is still in the middle of being
; defined. Our strategy is to pretend it
; has finished, and then start it again.
; Finish current link
USEPATH hyperlinks()
t$=\address ; remember this for the next link
\x2=WCursX
\y2=WCursY+sizey
; Take a new line
Gosub line_break
; Add a new link
AddItem hyperlinks()
USEPATH hyperlinks()
\address=t$ ; feed the link back in again
\x1=WCursX
\y1=WCursY
EndIf
Next a
WColour 1 ; Return colour to default
Return
;
; Text positions
;
.line_break
xpos=startx
ypos=ypos+sizey
WLocate xpos,ypos
offset=0
;If preview=Off Gosub check_wrap
Return
.new_paragraph
xpos=startx
ypos=ypos+sizey+sizey
WLocate xpos,ypos
offset=0
Return
; FONT Routines
.use_font
; Control the font used, depending on size and attributes
style.b=0
If underlined=On style=style+1
If bold=On style=style+2
If italic=On style=style+4
WindowFont size,style
; Alter how much space a newline takes up, depending
; on the size of the font used.
Select size
Case 0
sizey=13
sizex=5
Case 1
sizey=28
sizex=12
Case 2
sizey=24
sizex=10
Case 3
sizey=18
sizex=7
Case 4
sizey=15
sizex=6
Case 5
sizey=13
sizex=5
Case 6
sizey=11
sizex=4
End Select
If italic=On sizex=sizex+1
If bold=On sizex=sizex+2
;
Return
.prepare_fonts
f$="times.font"
LoadFont 6,f$,11
LoadFont 5,f$,13
LoadFont 4,f$,15
LoadFont 3,f$,18
LoadFont 2,f$,24
LoadFont 1,f$,28
LoadFont 0,"helvetica.font",13
Return
.open_display
;
; Define and open a Screen and Window
;
; Define a BitMap
BitMap 0,640,height+#screen_height,4
; The display is 4 deep, i.e. 16 colours!
; Define menus
MenuTitle 0,0,"Project"
MenuItem 0,0,0,0,"Load ","L"
MenuItem 0,0,0,1,"Save ","S"
MenuItem 0,0,0,2,"About "
MenuItem 0,0,0,3,"Quit ","Q"
; Define Gadgets
PropGadget 0,-16,0,128+2+1024,1,16,244
; Open a Special Window
Window 0,0,0,640,256,$0+$0+$20000+$20+$8+$400+$80+$1000,"SuperWindow",1,2,0,0
SetMenu 0
SetVProp 0,1,0,(10/height)
Redraw 0,1
Gosub prepare_fonts
WindowFont 0
Return
.goodbye
CloseWindow 0
CloseScreen 0
End